// import { deleteChargeCostApi, submitQuotationApi } from "@/api/waybillManagement/businessWaybill/waybillQuotation";
import { warehouseShipmentQuotationApi } from "@/api/waybillManagement/warehouseShipment";
import { deleteWarehouseOrderShipmentCostApi } from "@/api/waybillManagement/warehouseShipment";
import { Modal, message } from "ant-design-vue";
import { Ref, createVNode } from "vue";
import { ExclamationCircleOutlined } from "@ant-design/icons-vue";
export default function OperationHook(state: {
  drawerOpts: Base.DrawerOpts;
  passData: Ref<WarehouseWaybill.ListRows>;
  dialogOpts: Base.DialogOpts;
  formState: Ref<any>;
  emit: any;
  getQueryList: () => void;
}) {
  const { drawerOpts, dialogOpts, passData, formState, emit, getQueryList } = state;
  // 查看发票
  const showInvoiceHandle = () => {
    drawerOpts.width = "1200px";
    drawerOpts.title = "查看发票";
    drawerOpts.type = 1;
    drawerOpts.passData = { id: passData.value.warehouseBillNum, ...passData.value };
    drawerOpts.component = "ShowInvoice";
    drawerOpts.visible = true;
  };
  // 新增附加费
  const addChargeHandle = () => {
    dialogOpts.width = "520px";
    dialogOpts.title = "添加附加费";
    dialogOpts.type = 1;
    dialogOpts.passData = passData.value;
    dialogOpts.component = "AddCharge";
    dialogOpts.visible = true;
  };
  // 删除附加费
  const deleteChargeCostHandle = (row: Base.GeneraDataType) => {
    Modal.confirm({
      title: "是否删除当前附加费?",
      icon: createVNode(ExclamationCircleOutlined),
      onOk() {
        return deleteWarehouseOrderShipmentCostApi({ id: row.id }).then((res: any) => {
          const { code } = res;
          if (code === 200) {
            message.success("删除成功!");
            getQueryList();
            // if (passData.value.orderShipmentQuotationId) initInfo(passData.value.orderShipmentQuotationId as unknown as string);
            // else init(passData.value.shipmentId);
          }
        });
      }
    });
  };
  // // 修改客户备注
  // const modifyRemarkHandle = () => {
  //   dialogOpts.title = `修改客户备注`;
  //   dialogOpts.width = "520px";
  //   dialogOpts.type = 1;
  //   dialogOpts.component = "ModifyRemark";
  //   dialogOpts.passData = passData.value;
  //   dialogOpts.visible = true;
  // };
  // 修改客户备注
  // const modifyInnerRemarkHandle = () => {
  //   dialogOpts.title = `修改内部备注`;
  //   dialogOpts.width = "520px";
  //   dialogOpts.type = 2;
  //   dialogOpts.component = "ModifyRemark";
  //   dialogOpts.passData = passData.value;
  //   dialogOpts.visible = true;
  // };
  // 查看材积明细
  // const showBoxInfoHandle = () => {
  //   drawerOpts.width = "1200px";
  //   drawerOpts.title = "查看材积明细";
  //   drawerOpts.type = 1;
  //   drawerOpts.passData = passData.value;
  //   drawerOpts.component = "BoxInfo";
  //   drawerOpts.visible = true;
  // };
  // 提交/重新报价
  const submitHandle = () => {
    const params = {
      id: formState.value.quotationId ? formState.value.quotationId : undefined,
      warehouseBillId: formState.value.id
    };
    return warehouseShipmentQuotationApi(params).then((res: any) => {
      const { code } = res;
      if (code === 200) {
        message.success("操作成功!");
        emit("submit");
      }
    });
  };
  return {
    showInvoiceHandle,
    addChargeHandle,
    deleteChargeCostHandle,
    // modifyRemarkHandle,
    // modifyInnerRemarkHandle,
    // showBoxInfoHandle,
    submitHandle
    // updateHandle
  };
}
